package in.muton.panels.paginator.components.badges;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.panels.images.ImageWithLink;
import in.muton.edushare.url.EduShareURLPanel;
import in.muton.panels.paginator.badgehelpers.course.GroupBadgeInterface;

import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.Groups;

public class GroupBadge extends EdusharePanel {
	private IModel<Groups> model;
	private GroupBadgeInterface gbi;
	
	public IModel<Groups> getModel() {
		return model;
	}

	public void setModel(IModel<Groups> model) {
		this.model = model;
	}

	public GroupBadge(String id, IModel<Groups> model, EduShareBasePage page) {
		super(id, model, page);
		setModel(model);
		gbi = new GroupBadgeInterface();
		add(CSSPackageResource.getHeaderContribution(GroupBadge.class,
				"badge.css"));
		add(new ImageWithLink("groupImg", getModel(),
				ApplicationConstants.FILE_SUFFIX_THUMB));
		add(new EduShareURLPanel("groupUrl", getModel()));
		add(new Label("desc", StringUtil.ellipsis(getModel().getObject()
				.getDescription(), 300)).setEscapeModelStrings(false));
		add(new Link<Void>("delete") {
			private static final long serialVersionUID = 1639366604780941607L;
			@Override
			public void onClick() {
				setError(gbi.removeGroup(GroupBadge.this.getModel()));
			}
			@Override
			public boolean isVisible() {
				return gbi != null
						&& gbi.isAdmin(GroupBadge.this.getModel().getObject());
			}
		});
	}

	private static final long serialVersionUID = -4931062355588308468L;
}
